home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / Graphics3D / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.6 KB  |  203 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWPRHDLR_H
  31. #include "FWPrHdlr.h"            // FW_CPrintHandler
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35. #ifndef FWCFMRES_H
  36. #include "FWCFMRes.h"            // FW_CSharedLibraryResourceFile, FW_gInstance
  37. #endif
  38.  
  39. #ifndef FWMENU_H
  40. #include "FWMenu.h"                // FW_CMenuBar, etc.
  41. #endif
  42.  
  43. #ifndef FWEVENT_H
  44. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  45. #endif
  46.  
  47. #ifndef FWRECSHP_H
  48. #include "FWRecShp.h"            // FW_CRectShape
  49. #endif
  50.  
  51. #ifndef FWPICSHP_H
  52. #include "FWPicShp.h"            // FW_PPicture, FW_CPictureShape
  53. #endif
  54.  
  55. #ifndef FWRRCSHP_H
  56. #include "FWRRcShp.h"            // FW_CRoundRectShape
  57. #endif
  58.  
  59. #ifndef FWCMD_H
  60. #include "FWCmd.h"                // FW_CCommand
  61. #endif
  62.  
  63. #include "FWFileSp.h"
  64. #include "FWFileOp.h"
  65.  
  66. //========================================================================================
  67. #ifdef FW_BUILD_MAC
  68. #pragma segment Graphics3D
  69. #endif
  70.  
  71. FW_DEFINE_AUTO(CGraphics3DFrame)
  72.  
  73. //========================================================================================
  74. CGraphics3DFrame::CGraphics3DFrame(Environment* ev, ODFrame* odFrame, 
  75.                                     FW_CPresentation* presentation, 
  76.                                     CGraphics3DContent* content)
  77.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  78.   fViewer(NULL)
  79. {
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. CGraphics3DFrame::~CGraphics3DFrame()
  84. {
  85.     ::Q3ViewerDispose(fViewer);
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. void 
  90. CGraphics3DFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  91. {        
  92.     FW_CFrame::FacetAdded(ev, facet, facetCount);
  93.     ODPlatformWindow windowPtr = this->GetWindow(ev)->GetPlatformWindow(ev);
  94.     // Get rectangle enclosing the window’s content region.
  95.     Rect myRect = windowPtr->portRect;
  96.     // Create a new viewer object in entire content region
  97.     fViewer = ::Q3ViewerNew((CGrafPtr)windowPtr, &myRect, kQ3ViewerDefault);
  98.     FW_CRect frameRect = this->GetBounds(ev);
  99.     
  100. /*    FW_CAcquiredODTransform tForm = facet->AcquireExternalTransform(ev, facet->GetCanvas(ev));
  101.     ODPoint odPt;
  102.     tForm->GetOffset(ev, &odPt);
  103.     FW_CPoint fwPt(odPt);
  104.     frameRect.Offset(fwPt.x, fwPt.y);
  105. */    
  106.     Rect r = frameRect.AsPlatformRect();
  107.     short anErr = Q3ViewerSetBounds(fViewer, &r);
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. void 
  112. CGraphics3DFrame::FrameShapeChanged(Environment* ev)
  113. {
  114.     FW_CFrame::FrameShapeChanged(ev);
  115.     FW_CRect frameRect = this->GetBounds(ev);    // Get new frame rect
  116.     Rect r = frameRect.AsPlatformRect();
  117.     short anErr = ::Q3ViewerSetBounds(fViewer, &r);
  118.     this->Invalidate(ev, frameRect);            
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. void 
  123. CGraphics3DFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  124. {
  125.     FW_CPlatformGraphicContext pc(ev, odFacet, invalidShape);
  126.     FW_CRect frameRect = this->GetBounds(ev);    // Get new frame rect
  127.     Rect r = frameRect.AsPlatformRect();
  128.     short anErr = ::Q3ViewerSetBounds(fViewer, &r);
  129.     
  130.     ::Q3ViewerDraw(fViewer);
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. FW_Boolean 
  135. CGraphics3DFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  136. {    
  137.     FW_UNUSED(ev);
  138.     ODEventData* eventRec = ((FW_CMouseEvent)theMouseEvent).GetPlatformEvent();
  139.     FW_Boolean aBool = ::Q3ViewerEvent(fViewer, eventRec);
  140.     return TRUE;
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. FW_Boolean 
  145. CGraphics3DFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  146.                                                     FW_Boolean isRoot)    // Override
  147. {
  148.     if (hasMenuFocus) {
  149.         menuBar->EnableCommand(ev, cOpenFileCmdID, TRUE);
  150.     }
  151.     return false;
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. FW_Boolean 
  156. CGraphics3DFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  157. {
  158.     FW_Boolean menuHandled = true;
  159.     switch (theMenuEvent.GetCommandID(ev)) { 
  160.         case cOpenFileCmdID:         
  161.             OSType fileType = '3DMF';
  162.             FW_COpenFileParameters openFileParam(&fileType, nil);
  163.             FW_OFileSpecification* fileSpec = FW_CChooseFile::ChooseFileToOpen(openFileParam);
  164.             FSSpec macSpec;
  165.             fileSpec->MacGetFSSpec(ev, &macSpec);
  166.             short refNum;
  167.             short anErr = FSpOpenDF(&macSpec, fsCurPerm, &refNum);
  168.             anErr = ::Q3ViewerUseFile(fViewer, refNum);
  169.             this->FrameShapeChanged(ev);
  170. //            FW_CRect frameRect = this->GetBounds(ev);
  171. //            this->Invalidate(ev, frameRect);            
  172.             break;
  173.         
  174.         default:
  175.             menuHandled = false;
  176.     }
  177.     return menuHandled;
  178. }
  179.  
  180. //------------------------------------------------------------------------------
  181. FW_CPrintHandler* 
  182. CGraphics3DFrame::NewPrintHandler(Environment* ev)
  183. {
  184.     FW_CPart* part = GetPart(ev);
  185.     return new FW_CPrintHandler(part, this);
  186. }
  187.  
  188. //------------------------------------------------------------------------------
  189. FW_Boolean 
  190. CGraphics3DFrame::IsCurrentlyPrintable(Environment* ev) const
  191. {
  192.     return TRUE;
  193. }
  194.  
  195. //------------------------------------------------------------------------------
  196. void 
  197. CGraphics3DFrame::GetPrintContentExtent(Environment *ev, FW_CPoint& extent) const
  198. {
  199.     FW_CRect frameRect = this->GetBounds(ev);
  200.     extent = frameRect.Size();
  201. }
  202.  
  203.